home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
409_01
/
svga.asm
< prev
next >
Wrap
Assembly Source File
|
1993-10-21
|
35KB
|
1,024 lines
;****************************************************************************
;*
;* SuperVGA Test Library
;*
;* Copyright (C) 1993 SciTech Software
;* All rights reserved.
;*
;* Filename: $RCSfile: svga.asm $
;* Version: $Revision: 1.2 $
;*
;* Language: 80386 Assembler
;* Environment: IBM PC (MS DOS)
;*
;* Description: Assembly language support routines for the SuperVGA test
;* library.
;*
;* $Id: svga.asm 1.2 1993/10/22 08:58:40 kjb release $
;*
;****************************************************************************
IDEAL
JUMPS
P386 ; Use 386 instructions
MODEL large
CRTC EQU 3D4h ; Port of CRTC registers
VGABufferSeg EQU 0A000h ; Segment of VGA display memory
DATASEG
COMM _maxx:WORD
COMM _maxy:WORD
COMM _maxcolor:DWORD
COMM _bytesperline:WORD
COMM _pagesize:DWORD
COMM _curBank:WORD
COMM _bankSwitch:DWORD
COMM _extendedflipping:WORD
COMM _bankAdjust:WORD
COMM _writeBank:DWORD; Relocated write bank routine
COMM _readBank:DWORD ; Relocated read bank routine
COMM _pageFlip:DWORD ; Relocated page flip routine
OriginOffset dw 0 ; Starting offset within bank
BankOffset dw 0 ; Starting bank in video memory
CODESEG
MACRO procstart name ; Set up model independant proc
PROC name
PUBLIC name
ENDM
MACRO procend name ; End procedure macro
ENDP name
ENDM
;----------------------------------------------------------------------------
; void putPixel16(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry: x - X coordinate of pixel to draw
; y - Y coordinate of pixel to draw
; color - Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart __putPixel16
ARG x:WORD, y:WORD, color:DWORD
push bp ; Set up stack frame
mov bp,sp
; Compute the pixel's address in video buffer
mov ax,[y]
mov bx,[x]
mul [_bytesPerLine] ; DX:AX := y * BytesPerLine
mov cl,bl ; CL := low-order byte of x
shr bx,3 ; BX := x/8
add bx,ax
adc dx,0 ; DX:BX := y*BytesPerLine + x/8
add bx,[OriginOffset] ; DX:BX := byte offset in video buffer
adc dx,[BankOffset]
cmp dl,[BYTE _curBank]
je @@NoChange
mov ax,dx
call setBank
@@NoChange:
mov ax,VGABufferSeg
mov es,ax ; ES:BX := byte address of pixel
mov ah,1 ; AH := unshifted bit mask
and cl,7 ; CL := x & 7
xor cl,7 ; CL := # bits to shift left
; set Graphics Controller Bit Mask register
shl ah,cl ; AH := bit mask in proper postion
mov dx,3CEh ; GC address register port
mov al,8 ; AL := Bit Mask Register number
out dx,ax
; set Graphics Controller Mode register
mov ax,0205h ; AL := Mode register number
; AH := Write mode 2 (bits 0,1)
; Read mode 0 (bit 3)
out dx,ax
; set data rotate/Function Select register
mov ax,3 ; AL := Data Rotate/Func select reg #
out dx,ax
; set the pixel value
mov al,[es:bx] ; latch one byte from each bit plane
mov al,[BYTE color] ; AL := pixel value
mov [es:bx],al ; update all bit planes
; restore default Graphics Controller registers
mov ax,0FF08h ; default bit mask
out dx,ax
mov ax,0005 ; default mode register
out dx,ax
mov ax,0003 ; default function select
out dx,ax
pop bp
ret
procend __putPixel16
;----------------------------------------------------------------------------
; void putPixel256(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry: x - X coordinate of pixel to draw
; y - Y coordinate of pixel to draw
; color - Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart __putPixel256
ARG x:WORD, y:WORD, color:DWORD
push bp ; Set up stack frame
mov bp,sp
mov ax,[y]
mul [_bytesperline]
add ax,[x]
adc dx,0 ; DX:AX := y * BytesPerLine + x
add ax,[OriginOffset]
adc dl,[BYTE BankOffset]; DL := bank number
mov bx,ax ; BX := Offset in buffer
cmp dl,[BYTE _curBank]
je @@NoChange
mov ax,dx
call setBank
@@NoChange:
mov ax,VGABufferSeg
mov es,ax ; ES:BX := byte address of pixel
mov al,[BYTE color]
mov [es:bx],al ; Replace the pixel
pop bp
ret
procend __putPixel256
;----------------------------------------------------------------------------
; void putPixel32k(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry: x - X coordinate of pixel to draw
; y - Y coordinate of pixel to draw
; color - Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart __putPixel32k
ARG x:WORD, y:WORD, color:DWORD
push bp ; Set up stack frame
mov bp,sp
mov ax,[y]
mul [_bytesperline]
mov bx,[x]
shl bx,1
add ax,bx
adc dx,0 ; DX:AX := y * BytesPerLine + x * 2
add ax,[OriginOffset]
adc dl,[BYTE BankOffset]; DL := bank number
mov bx,ax ; BX := Offset in buffer
cmp dl,[BYTE _curBank]
je @@NoChange
mov al,dl
call setBank
@@NoChange:
mov ax,VGABufferSeg
mov es,ax ; ES:BX := byte address of pixel
mov ax,[WORD color]
mov [es:bx],ax ; Replace the pixel
pop bp
ret
procend __putPixel32k
;----------------------------------------------------------------------------
; void putPixel64k(int x,int y,long color)
;----------------------------------------------------------------------------
; Routine sets the value of a pixel in native VGA graphics modes.
;
; Entry: x - X coordinate of pixel to draw
; y - Y coordinate of pixel to draw
; color - Color of pixel to draw
;
;----------------------------------------------------------------------------
procstart __putPixel64k
ARG x:WORD, y:WORD, color:DWORD
push bp ; Set up stack frame
mov bp,sp
mov ax,[y]
mul [_bytesperline]
mov bx,[x]
shl bx,1
add ax,bx
adc